<?php
/**
 * @copyright   Copyright (c) 2017 https://www.sapixx.com All rights reserved.
 * @license     Licensed (http://www.apache.org/licenses/LICENSE-2.0).
 * @author      pillar<ltmn@qq.com>
 * 支付有礼
 */
namespace app\allwin\controller\home;
use think\facade\Request;
use app\common\controller\Home;
use app\common\facade\WechatMp;
use app\allwin\model\AllwinGift;
use app\allwin\model\AllwinGiftStore;

class Gift extends Home{

    protected $member_miniapp_id; //站点参数

    /**
     * 初始化当前应用管理员是不是联盟城市账户
     * @return void
     */
    public function initialize() {
        parent::initialize();
        $this->member_miniapp_id = Request::param('app');
        if(!$this->member_miniapp_id){
            $this->error('访问页面不存');
        }
    }
    /**
     * 分享赚钱营销
     */
    public function index(int $id){
        $gift = AllwinGift::where(['member_miniapp_id' => $this->member_miniapp_id,'id' => $id,'is_lock' => 0])->find();
        if(empty($gift)){
            $this->error('访问页面不存');
        }
        $view['store']     = AllwinGiftStore::where(['member_miniapp_id' => $this->member_miniapp_id,'gift_id' => $id,'is_lock' => 0])->select();
        $view['gift']      = $gift;
        $view['title']     = $gift->title;
        $view['weconfig']  = WechatMp::jsApiList($this->member_miniapp_id);
        $view['share_url'] = urls('Allwin/gift/index',$this->member_miniapp_id,['id' => $id]);
        $this->view->engine->layout(false);
        return view()->assign($view);
    }
}